package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.user.OrdersSubmitService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "下单相关功能")
public class OrderController {

    @Autowired
    private OrdersSubmitService orderSubmitService;


    @PostMapping("/submit")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO dto) {
        OrderSubmitVO vo = orderSubmitService.submit(dto);
        return Result.success(vo);

    }
    @ApiOperation("查询历史订单")
    @GetMapping("/historyOrders")
    public Result<PageResult> historyOrders(OrdersPageQueryDTO dto){
       PageResult result= orderSubmitService.historyOrders(dto);
       return Result.success(result);
    }
    @GetMapping("/orderDetail/{orderId}")
    public Result<OrderVO> selectOrderDetail(@PathVariable Long orderId){
      return  orderSubmitService.selectByOrderId(orderId);
    }
    @GetMapping("queryOrdersCheckStatus")
    public Result<PageResult>queryOrdersCheckStatus(OrdersPageQueryDTO dto){
        PageResult result= orderSubmitService.historyOrders(dto);
        return Result.success(result);
    }
    @PostMapping("repetition/{id}")
    public Result<String>Repetition(@PathVariable Long id){
        orderSubmitService.saveShoppingById(id);
        return Result.success();
    }
}
